package caiziyou.com.designpattern.principle.opc.improve;

public class OcpDemo {

	public static void main(String[] args) {
		GraphicEditer graphicEditer = new GraphicEditer();
		graphicEditer.drawShape(new Rectangle());
		graphicEditer.drawShape(new Circle());
		graphicEditer.drawShape(new Triangle());
		graphicEditer.drawShape(new OtherGraphic());
	}
}

class GraphicEditer {
	public void drawShape(Shape s) {
		s.draw();
	}
}

abstract class Shape {
	public abstract void draw();
}

class Circle extends Shape {

	@Override
	public void draw() {
		System.out.println("绘制圆形");
	}
}

class Rectangle extends Shape {

	@Override
	public void draw() {
		System.out.println("绘制矩形");
	}
}

class Triangle extends Shape {

	@Override
	public void draw() {
		System.out.println("绘制三角形");
	}
}
//新增一个图形只需要
class OtherGraphic extends Shape{

	@Override
	public void draw() {
		System.out.println("绘制其他图形");
	}
	
}
